//
//  InvestDetailTableViewController.m
//  DaoZiJinFu
//
//  Created by woker on 16/6/27.
//  Copyright © 2016年 iwoker. All rights reserved.
//

#import "InvestDetailTableViewController.h"
#import "InvestmentDetailView.h"

@interface InvestDetailTableViewController () {
    NSArray *listArray;
    InvestmentDetailView *headerView;
}

@end

@implementation InvestDetailTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BACKGROUND_COLOR;
    [self leftButton:nil];
    
    listArray = @[@"投资期限",@"投资时间",@"起息时间",@"到期时间",@"回款时间",@"回款方式"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 52;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 98+24/75.0*SCREEN_WIDTH;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    headerView = [InvestmentDetailView loadView];
    headerView.investMoney.text = _investModel.total_amount;
    headerView.yieldsLab.text = [NSString stringWithFormat:@"%.2lf%%",[_investModel.product_annual_gains doubleValue]*100];
    switch (_segmentValue) {
        case 0:
            headerView.incomeTextLab.text = @"预计收益（元）";
            float money = [DZNsstringUtil floatInto:[_investModel.gains_amount doubleValue]];
            headerView.incomeLab.text = [NSString stringWithFormat:@"%.2lf",money];
            break;
        default:
        {headerView.incomeTextLab.text = @"获得收益（元）";
            float money = [DZNsstringUtil floatInto:[_investModel.actual_gains_amount doubleValue]];
            headerView.incomeLab.text = [NSString stringWithFormat:@"%.2lf",money];
        }break;
    }
    return headerView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:INVEST_DETAIL];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:INVEST_DETAIL];
        cell.textLabel.text = listArray[indexPath.row];
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
        cell.textLabel.textColor = DEFAULTCOLOR;
        
        switch (indexPath.row) {
            case 0:cell.detailTextLabel.text = [NSString stringWithFormat:@"%@天",_investModel.product_day_number];break;
            case 1:cell.detailTextLabel.text = _investModel.pay_time;break;
            case 2:cell.detailTextLabel.text = _investModel.interest_start_date;break;
            case 3:cell.detailTextLabel.text = _investModel.interest_end_date;break;
            case 4:cell.detailTextLabel.text = _investModel.back_section_time;break;
            case 5:cell.detailTextLabel.text = @"到期还本付息，返还到账户余额";break;
                
            default:
                break;
        }
    }
    cell.selectionStyle = UIAccessibilityTraitNone;
    return cell;
}

@end
